package cn.gok;

import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;

/**
 * @ClassName Test
 * @Description TODO
 * @Author Oscar
 * @Date 9:44 2022/7/4
 * @Version 1.0
 **/
public class Test {
    public static void main(String[] args) {
        System.out.println("hello word!");
        Test test=new Test();
//        test.bianString();
//        test.ziMu();
//        test.initAllay1();
//        test.sortAllay();
//        test.dayWork();
        test.toPassword();
    }

    /**
     * String int2Str(int num);
     */
    public void bianString(){
//        字符串和其他类型的转换
        int a=123;
        String str=Integer.valueOf(a).toString();
        String str2=new Integer(a).toString();

        System.out.println("int转String:"+str+str2);
    }
//    打印26个字母
    public void ziMu(){
        int t='a';
        for (int i = 0; i < 26; i++) {
            System.out.println(t+i+"---"+t+i+32);
        }
    }
//    数位运算
    public void shuWei(){
        int i=9;
        int i2=-7;
        System.out.println(i>>2);
        System.out.println(i2<<2);
    }
//    初始化数组的两种方法
    class A{}
    public void initAllay1(){
        A as[]=new A[4];
        for (int i = 0; i < as.length; i++) {
            as[i]=new A();
        }
        System.out.println(as.toString());
    }
    public void initAllay2(){
        A as[]= {new A(),new A(),new A(),new A(),};
        System.out.println(as.toString());
    }
//    二分法排序
    public void sortAllay(){
        int a[]={2,5,8,6,1,4,3};
        Arrays.sort(a);
        for(int i:a){
            System.out.print(i+" ");
        }
//        将排序好的数组进行二分查找
        System.out.println();
        System.out.println(Arrays.binarySearch(a,3));
    }
//    day1作业：生成随机密码字符串并输出，要求同时包含大写字母及数字，至少六位
    public void dayWork(){
        String m1[]={"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};
        String m2[]={"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};
        String m3[]={"0","1","2","3","4","5","6","7","8","9"};
        String password="";
//        随机生成数字，随机从三个数组内取值
        Random random = new Random();
        Scanner scanner=new Scanner(System.in);
        System.out.println("请输入要生成多少位密码：");
        int num=scanner.nextInt();
        for (int i = 0; i < num; i++) {
            int n=random.nextInt(3);
            switch (n){
                case 0:password+=m1[random.nextInt(26)];break;
                case 1:password+=m2[random.nextInt(26)];break;
                case 2:password+=m3[random.nextInt(10)];break;
            }
        }
        System.out.println("生成的随机密码是："+password);
    }
//    第二种做法
    public void toPassword(){
        String password="";
        Random random = new Random();
        Scanner scanner=new Scanner(System.in);
        System.out.println("请输入要生成多少位密码：");
        int num=scanner.nextInt();
        for (int i = 0; i < num; i++) {
            int n=random.nextInt(3);
            switch (n){
                case 0:password+=(char) ('a'+random.nextInt(26));break;
                case 1:password+=(char) ('A'+random.nextInt(26));break;
                case 2:password+=(random.nextInt(10)+"");break;
            }
        }
        System.out.println("生成的随机密码是："+password);
    }
}
